const uilts = require("./utils.js");
const fs = require("fs");
const config = {
  // inDir: __dirname + "/素材",
  // outDir: __dirname + "/素材",
  inDir: "F:/测试/1111.印象笔记",
  outDir: "F:/测试/1111.印象笔记",
};

let files = fs.readdirSync(config.inDir);

files.forEach((file, index) => {
  let curPath = config.inDir + "/" + file;
  if (file.endsWith(".html") && !file.endsWith("_index.html") && !fs.statSync(curPath).isDirectory()) {
    let filename = file.substring(0,file.length-4)
    let outPath = config.outDir + "/" + filename + "md";
    let html = fs.readFileSync(curPath, "utf-8");
    html = html.replace(/\u0000/g,"")
    let md = uilts.htmlToMarkdown(html);
    const fd = fs.openSync(outPath, "w");
    // fs.writeFileSync(fd, "tag:" + md.tag + "\n\n" +  md.content);
    fs.writeFileSync(fd, md.content);
    console.log(outPath + ",生成成功")
  }
});
